﻿namespace HiMap.MapControls.Tools
{
    using HiMap.Geometry;
    using System;
    using System.Windows.Forms;

    public class ToolZoomIn : ToolTrack
    {
        private double _scale;

        public ToolZoomIn()
        {
            try
            {
                this._scale = 0;
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }

        public ToolZoomIn(double scale)
        {
            try
            {
                this._scale = scale;
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }

        protected override void Stop(IGeometry geo, int x, int y)
        {
            try
            {
                if (geo != null)
                {
                    IEnvelope envelope = (IEnvelope) geo;
                    if (envelope.MinX != envelope.MaxX)
                    {
                        IPoint point = new PointClass();
                        point.X = (envelope.MaxX + envelope.MinX) / 2;
                        point.Y = (envelope.MaxY + envelope.MinY) / 2;
                        double num = (envelope.MaxX - envelope.MinX) / (base.Map.Map.Envelope.MaxX - base.Map.Map.Envelope.MinX);
                        double num2 = base.Map.Map.MapScale * num;
                        if ((this._scale > 0) && (num2 < this._scale))
                        {
                            num2 = this._scale;
                        }
                        base.Map.Map.CenterAt = point;
                        base.Map.Map.MapScale = num2;
                        base.Map.MapRefresh();
                    }
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
    }
}

